public class ListOfPredicates {

        
        private int size; 
        private int nbPredicateInArray;
        private Predicate[] pre;  
        
        public ListOfPredicates (int n) {         
                size = n;
                nbPredicateInArray = 0;
                pre =  new Predicate[n];
                }

        public boolean full () {
                return nbPredicateInArray == size;
                }
                public boolean empty () {
                return nbPredicateInArray == 0;
                }
                
                public Predicate retrieve (int numberOfType) {
                        return pre[numberOfType];
                }
                

                public boolean addPredicate (String nameOfPredicate) {
                 // I change this method because in the parser I need to add with specific name .       
                                if (getNbPredicateInArray() < getSize()) {
                                        pre[getNbPredicateInArray()] = new Predicate(nameOfPredicate);
                                        nbPredicateInArray++;
                                                return true;
                                }
                                else
                                        return false;
                        }

        
                public boolean removePredicate (String nameOfType) {
                 
                                for (int i =0 ; i < size; i++) {
                                        if (pre[i].getName().equals(nameOfType) ){
                                                
                                                for(int p = i+1 ; p < nbPredicateInArray ; p++){
                                                        pre[p-1] = pre[p];
                                                }
                                                nbPredicateInArray--;   
                                                return true ;
                                        }
                                        
                                }
                                return false ;
                }
                
                public int findPredicate(String nameOfPredicate){
                        for(int i = 0 ; i < getSize() ; i++){
                                if(pre[i].getName().equals(nameOfPredicate)){
 
                                        return i ;
                                }
                        }
                        return -1 ;
                }
                
                public Predicate findPredicateObj(String nameOfPredicate){//I added this method with changing return type because in parser I need to find some predicate and modify on it 
                    for(int i = 0 ; i < getNbPredicateInArray() ; i++){   // example LP.findPredicateObj("?????").getLT().addType("????");
                            if(pre[i].getName().equals(nameOfPredicate)){

                                    return pre[i]; 
                            }
                    }
                    return null ;
            }
                
      public void display(){
        	if(nbPredicateInArray>0){
        	   System.out.println("=====================================");
               for(int i=0 ; i<getNbPredicateInArray() ; i++){
                 pre[i].display();
                 System.out.println("=====================================");
               }
               System.out.println("=====================================");
        	}
       }


                public int getSize() {
                        return size;
                }

                public int getNbPredicateInArray() {
                        return nbPredicateInArray;
                }

                public Predicate[] getPre() {
                        return pre;
                }

                public void setSize(int size) {
                	if(size>nbPredicateInArray)
                        this.size = size;
                    else System.out.println(" you write size less than number of element in the array , please rewrite the size");
                
                }

                public void setNbPredicateInArray(int nbPredicateInArray) {
                        this.nbPredicateInArray = nbPredicateInArray;
                }

                public void setPre(Predicate[] pre) {
                        this.pre = pre;
                }

                
        
        
}
